package com.ccys.cms.controller.formulation;


import com.ccys.cms.service.formulation.RoutePatientService;
import com.ccys.common.vo.ResponseResult;
import com.ccys.db.dto.web.formulation.RoutePatientDto;
import com.ccys.db.dto.web.productAndService.NumEnum;
import com.ccys.db.entity.TblFormulationRoutePatient;
import com.ccys.db.mapper.TblFormulationRoutePatientMapper;
import com.ccys.db.vo.web.formulation.RoutePatientVo;
import com.ccys.db.vo.web.productAndService.IdNameVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/formulation")
@Api(tags = "routePatient管理")
public class RoutePatientController {


    @Resource
    private RoutePatientService routePatientService;


    @Resource
    private TblFormulationRoutePatientMapper mapper;


    @PostMapping("routePatient")
    @ApiOperation("新增")
    @Transactional
    public ResponseResult insert(TblFormulationRoutePatient model) {

        int i = routePatientService.insertOrUpdate(model);
        return ResponseResult.update(i);
    }


    @PutMapping("routePatient")
    @ApiOperation("修改")
    @Transactional
    public ResponseResult update(TblFormulationRoutePatient model) {

        int i = routePatientService.insertOrUpdate(model);
        return ResponseResult.update(i);
    }


    @DeleteMapping("routePatient")
    @ApiOperation("根据Id删除")
    @Transactional
    public ResponseResult delete(String id) {

        TblFormulationRoutePatient model = new TblFormulationRoutePatient();
        model.setId(id);
        model.setDelFlag(NumEnum.DEL.getCode());
        int i = routePatientService.updateEntityById(model);
        return ResponseResult.update(i);
    }


    @GetMapping("routePatient")
    @ApiOperation(value = "查询分页", notes = "排序字段   t3.name (formulationName)/ t4.name(routeDoctorName) /t1.name(指的route(Patient)列) / t1.disp_order / t1.status / t2.user_fullname / t1.created_on ")
    public ResponseResult<PageInfo<RoutePatientVo>, Object> getPage(RoutePatientDto dto) {

        return routePatientService.getPage(dto);
    }


    @GetMapping("routePatient/list")
    @ApiOperation("根据formulationId以及doctorId查询patientList")
    public ResponseResult<List<IdNameVo>, Object> getList(String formulationId, String routeDoctorId) {
        List<IdNameVo> list = mapper.getRoutePatientList(formulationId, routeDoctorId);
        return ResponseResult.success(list);
    }


}
